package com.johnson.news.model.util;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public class NewsPreference {

	static NewsPreference pref;
	Context context;
	SharedPreferences mySharedPreferences;
	private final String TOKEN = "token";
	private final String LOGIN_STATE = "state";
	private final String LOGIN_NAME = "name";
	private final String CHANNEL_ID = "channel_id";
	private final String BEGIN_TIME = "begin_time";
	private final String END_TIME = "end_time";
	private final String LAUNCH_MD5 = "md5";

	public static NewsPreference getinstance(Context context){
		if(pref == null){
			pref = new NewsPreference(context);
		}
		return pref;
	}
	
	public NewsPreference(Context context) {
		// TODO Auto-generated constructor stub
		this.context = context;
		mySharedPreferences= context.getSharedPreferences("news_pref", 
				Activity.MODE_PRIVATE);
	}
	
	public void setToken(String token){
		SharedPreferences.Editor editor = mySharedPreferences.edit();
		editor.putString(TOKEN, token); 
		editor.commit(); 
	}
	
	public String getToken(){
		return mySharedPreferences.getString(TOKEN, "");
	}
	
	public void setLoginState(boolean islogin){
		SharedPreferences.Editor editor = mySharedPreferences.edit();
		editor.putBoolean(LOGIN_STATE, islogin); 
		editor.commit(); 
	}
	
	public boolean getLoginState(){
		return mySharedPreferences.getBoolean(LOGIN_STATE, false);
	}
	
	public void setLoginName(String name){
		SharedPreferences.Editor editor = mySharedPreferences.edit();
		editor.putString(LOGIN_NAME, name); 
		editor.commit(); 
	}
	
	public String getLoginName(){
		return mySharedPreferences.getString(LOGIN_NAME, "");
	}
	
	public void setPushChannelId(String channelid){
		SharedPreferences.Editor editor = mySharedPreferences.edit();
		editor.putString(CHANNEL_ID, channelid); 
		editor.commit(); 
	}
	
	public String getPushChannelId(){
		return mySharedPreferences.getString(CHANNEL_ID, "");
	}
	
	public void setBeginTime(String start){
		SharedPreferences.Editor editor = mySharedPreferences.edit();
		editor.putString(BEGIN_TIME, start); 
		editor.commit(); 
	}
	
	public String getBeginTime(){
		return mySharedPreferences.getString(BEGIN_TIME, "");
	}
	
	public void setEndTime(String endtime){
		SharedPreferences.Editor editor = mySharedPreferences.edit();
		editor.putString(END_TIME, endtime); 
		editor.commit(); 
	}
	
	public String getEndTime(){
		return mySharedPreferences.getString(END_TIME, "");
	}
	
	public void setLaunchMd5(String md5){
		SharedPreferences.Editor editor = mySharedPreferences.edit();
		editor.putString(LAUNCH_MD5, md5); 
		editor.commit(); 
	}
	
	public String getLaunchMd5(){
		return mySharedPreferences.getString(LAUNCH_MD5, "");
	}


}
